﻿
@{
    ViewBag.Title = "PriceAdjustmentRequest";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<form id="form1">
    <div class="panel panel-default">
        <div class="panel-heading">
            筛选条件
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    <th class="formTitle">关键字</th>
                    <td class="formValue">
                        <input type="text" id="txtINPUTCODE" class="form-control" placeholder="药品代码 拼音 名称" />
                    </td>
                    <td class="formValue" colspan="3">
                        <input type="button" id="btn_search" class="btn btn-primary btn-md" value="查询" style="width:55px" />
                        <span style="color: red; margin-left:10px;">注：无法查询已申请调价但未执行的药品</span>
                    </td>
                </tr>
            </table>
        </div>       
    </div>
    <div class="gridPanel" style="margin-top:10px">
        <div class="gridPanel">
            <table id="gridYPInfoList"></table>
            <div id="gridPager" rel="form1"></div>
        </div>
    </div>
    <div class="gridPanel" style="margin-top:10px">
        <div class="panel-heading">
            调价明细
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    <th class="formTitle"><span class="required">*</span>批发价</th>
                    <td class="formValue">
                        <input type="text" id="txtPFJ" class="form-control" />
                    </td>
                    <th class="formTitle"><span class="required">*</span>零售价</th>
                    <td class="formValue">
                        <input type="text" id="txtLSJ" class="form-control" />
                    </td>
                    <th class="formTitle"><span class="required">*</span>执行文件</th>
                    <td class="formValue">
                        <input type="text" id="txtZXWJ" class="form-control" />
                    </td>
                    <th class="formTitle"><span class="required">*</span>执行时间</th>
                    <td class="formValue">
                        <input id="txtZXSJ" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")" onfocus="WdatePicker({ minDate: '%y-%M-#{%d+1}' })" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">原批发价</th>
                    <td class="formValue">
                        <input type="text" id="txtYPFJ" class="form-control newtouch_Readonly" />
                    </td>
                    <th class="formTitle">原零售价</th>
                    <td class="formValue">
                        <input type="text" id="txtYLSJ" class="form-control newtouch_Readonly" />
                        <input type="text" id="hidden_ypCode" hidden />
                    </td>
                </tr>
            </table>
        </div>
    </div>
</form>

@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 6 },
    F6Text = "申请"
})

<script>
    var $gridYpInfoList;
    $(function () {
        gridYPInfoList();
        $("#btn_search").click(function () {
            SearchYP();
        });
        $("#txtINPUTCODE").bind("keyup", function () {
            if (event.keyCode === 13) {
                SearchYP();
            }
        });
    });

    function gridYPInfoList() {
        $gridYpInfoList = $("#gridYPInfoList");
        $gridYpInfoList.dataGrid({
            postData: getSearchPostData(),
            url: "/DrugStorage/SelectAdjustPriceMedicineInfoList",
            height: $(window).height() - 310,
            colModel: [
                { label: "药品代码", name: "ypCode", width: 80, align: 'left' },
                { label: '药品名称', name: 'ypmc', width: 120, align: 'left' },
                { label: '药品规格', name: 'ypgg', width: 120, align: 'left' },
                { label: '定价单位', name: 'djdw', width: 80, align: 'left' },
                {
                    label: '批发价', name: 'pfj', width: 100, align: 'left',
                    formatter: function (val) {
                        return val.toFixed(4);
                    }
                },
                {
                    label: '零售价', name: 'lsj', width: 100, align: 'left',
                    formatter: function (val) {
                        return val.toFixed(4);
                    }
                },
                { label: '药品属性', name: 'yptssxmc', width: 80, align: 'left' },
                { label: '药品类别', name: 'yplb', width: 80, align: 'left' },
                { label: '剂量', name: 'jl', width: 80, align: 'left' },
                { label: '剂量单位', name: 'jldw', width: 80, align: 'left' },
                { label: '药库包装数', name: 'bzs', width: 80, align: 'left' },
                { label: '药库包装单位', name: 'bzdw', width: 80, align: 'left' },
                { label: '门诊拆零数', name: 'mzcls', width: 80, align: 'left' },
                { label: '门诊拆零单位', name: 'mzcldw', width: 80, align: 'left' },
                { label: '住院拆零数', name: 'zycls', width: 80, align: 'left' },
                { label: '住院拆零单位', name: 'zycldw', width: 80, align: 'left' },
                { label: '自负比例', name: 'zfbl', width: 80, align: 'left' },
                { label: '自负性质', name: 'zfxz', width: 80, align: 'left' },
                { label: '剂型', name: 'jxmc', width: 100, align: 'left' },
                { label: '生产厂家', name: 'ycmc', width: 150, align: 'left' },
                { label: '状态', name: 'zt', width: 80, align: 'left' },
                { label: '记账类型', name: 'jzlx', width: 100, align: 'left' },
                { label: '默认保质期', name: 'mrbzq', width: 80, align: 'left' }
            ],
            multiselect: false,
            pager: "#gridPager",
            sortname: 'ypCode desc',
            viewrecords: true,
            onSelectRow_page: function (rowid) {
                if (rowid) {
                    $("#txtPFJ").val('');
                    $("#txtLSJ").val('');
                    var getRowData = $("#gridYPInfoList").jqGrid('getRowData', rowid);
                    if (getRowData) {
                        $("#txtYPFJ").val(getRowData.pfj);
                        $("#txtYLSJ").val(getRowData.lsj);
                        $("#hidden_ypCode").val(getRowData.ypCode);
                    }
                }
            }
        });
    }

    function SearchYP() {
        $gridYpInfoList.jqGrid('setGridParam', {
            postData: getSearchPostData(), url: '/DrugStorage/SelectAdjustPriceMedicineInfoList',
        }).trigger("reloadGrid");
    }

    //查询条件
    function getSearchPostData() {
        var inputCode = $("#txtINPUTCODE").val();
        return { inputCode: inputCode };
    };

    //提交申请
    function newtouch_event_f6() {
        //校验数据
        if (!CheckData()) {
            return false;
        }
        $.najax({
            url: "/DrugStorage/SubmitRequuest",
            dataType: "json",
            data: { ypCode: $("#hidden_ypCode").val(), pfj: $("#txtPFJ").val(), lsj: $("#txtLSJ").val(), ypfj: $("#txtYPFJ").val(), ylsj: $("#txtYLSJ").val(), tzwj: $("#txtZXWJ").val(), zxsj: $("#txtZXSJ").val() },
            type: "POST",
            async: "false",
            success: function (data) {
                $.modalAlert("申请提交成功", 'success');
                $("#txtPFJ").val('');
                $("#txtLSJ").val('');
                $("#txtZXWJ").val('');
                $("#txtZXSJ").val('');
                $("#txtYPFJ").val('');
                $("#txtYLSJ").val('');
                $.loading(false);
            },
            errCallback: function (err) {
                $.loading(false);
            }
        });
    }


    //校验数据
    function CheckData() {
        //校验格式
        if ($("#txtYPFJ").val() === "") {
            $.modalAlert("请选择药品进行调价！", 'warning');
            return false;
        }
        if ($("#txtPFJ").val() === "") {
            $.modalAlert("批发价不能为空！", 'warning');
            return false;
        }
        if ($("#txtLSJ").val() === "") {
            $.modalAlert("零售价不能为空！", 'warning');
            return false;
        }
        if (isNaN($("#txtPFJ").val()) || isNaN($("#txtLSJ").val())) {
            $.modalAlert("批发价或零售价格式错误,请填写数字！", 'warning');
            return false;
        }        
        if ($("#txtZXWJ").val() === "") {
            $.modalAlert("执行文件不能为空！", 'warning');
            return false;
        }
        if ($("#txtZXSJ").val() === "") {
            $.modalAlert("执行时间不能为空！", 'warning');
            return false;
        }
        if ($("#txtPFJ").val() === $("#txtYPFJ").val() && $("#txtLSJ").val() === $("#txtYLSJ").val()) {
            $.modalAlert("批发价和零售价不能与原价相同！", "warning");
            return false;
        }
        return true;
    }
</script>
